home *** CD-ROM | disk | FTP | other *** search
- //*************************************************************************//
- // Filename: Bar.cpp
- // Autor: Christian Taulien of Strange Intelligence
- // Purpose: Bar management and display implementation for FreshBar
- // Creation: 17. Mai 1998
- //*************************************************************************//
-
- #include "global.h"
- #include "Bar.h"
- #include "WindowList.h"
- #include "TextMeasure.h"
- #include "VisualInfo.h"
-
- #include <clib/exec_protos.h>
- #include <clib/gadtools_protos.h>
- #include <clib/graphics_protos.h>
-
- #include <graphics/rastport.h>
-
- extern "C" void NewList(struct List *list);
-
- //******************************************************************//
- //******************************************************************//
- //
- // BarNodeC
- //
- //******************************************************************//
- //******************************************************************//
- ULONG BarNodeC::m_ulNextFreeID = 0;
-
- BarNodeC::BarNodeC(BarListC *arg_poBarList, char *arg_sName, ULONG arg_ulMaxValue)
- /*S*/
- {
- TRACE("Konstruktor");
- if (!arg_poBarList)
- {
- TRACE("Falscher Parameter!");
- throw;
- } // if
-
- // init the baseclassmembers
- ln_Succ = NULL;
- ln_Pred = NULL;
- ln_Type = NT_USER;
- ln_Pri = 0;
-
- // now our members
- m_oName = arg_sName;
- m_ulMaxValue = arg_ulMaxValue;
- m_ulCurrentValue = 0;
- m_bShowPercent = FALSE;
- m_ulID = ++m_ulNextFreeID;
- m_iPen = 3;
- m_iBPen = 0;
- m_eProgressMode = PM_Percent;
-
- AddTail(arg_poBarList, this);
- } // BarNodeC::BarNodeC()
- /*E*/
- BarNodeC::~BarNodeC()
- /*S*/
- {
- TRACE("Destruktor");
-
- // delete the name
- if (ln_Name)
- {
- delete ln_Name;
- } // if
-
- // if the node is in a list
- if (ln_Pred && ln_Succ)
- {
- Remove(this);
- } // if
- }
- /*E*/
- BarNodeC *BarNodeC::getNext(void)
- /*S*/
- {
- TRACE("getNext()");
- if (ln_Succ && ln_Succ->ln_Succ)
- {
- return (BarNodeC *) ln_Succ;
- } // if
-
- return NULL;
- }
- /*E*/
- BarNodeC *BarNodeC::getPrev(void)
- /*S*/
- {
- TRACE("getPrev()");
- if (ln_Pred && ln_Pred->ln_Pred)
- {
- return (BarNodeC *) ln_Pred;
- } // if
-
- return NULL;
- }
- /*E*/
- void BarNodeC::drawBar(BarWindowNodeC *arg_poBWNode,
- TextMeasureC *arg_poTeMe,
- ULONG arg_ulPosX,
- ULONG arg_ulPosY,
- ULONG arg_ulBarBreite,
- ULONG arg_ulBreite,
- ULONG arg_ulHoehe)
- /*S*/
- {
- TRACE("Entry");
- struct RastPort *poRPort = arg_poBWNode->getWindow()->RPort;
- VisualInfoC oVI(arg_poBWNode->getWindow());
- if (oVI.isOk())
- {
- TRACE("Visualinfo ok");
-
- // Bar-Title ausgeben
- SetAPen(poRPort, 1);
- Move(poRPort, arg_ulPosX, arg_ulPosY+arg_ulHoehe-5);
- Text(poRPort, (char *) m_oName, m_oName.getLength());
-
- int iPosX = arg_ulPosX + arg_ulBreite - arg_ulBarBreite;
- DrawBevelBox( poRPort,
- iPosX,
- arg_ulPosY,
- arg_ulBarBreite,
- arg_ulHoehe,
- GT_VisualInfo, (APTR) oVI,
- GTBB_Recessed, TRUE,
- TAG_DONE );
-
- fillBar(poRPort,
- arg_poTeMe,
- arg_ulPosX,
- arg_ulPosY,
- arg_ulBarBreite,
- arg_ulBreite,
- arg_ulHoehe);
- } // if
- }
- /*E*/
- void BarNodeC::fillBar(struct RastPort *arg_poRPort,
- TextMeasureC *arg_poTeMe,
- ULONG arg_ulPosX,
- ULONG arg_ulPosY,
- ULONG arg_ulBarBreite,
- ULONG arg_ulBreite,
- ULONG arg_ulHoehe)
- /*S*/
- {
- TRACE("Entry");
- arg_ulPosX++;
- arg_ulPosY++;
- arg_ulBreite-=2;
- arg_ulHoehe-=3;
- arg_ulBarBreite-=3;
-
- // der CurrentValuef dar nicht kleiner als null sein
- if (((int ) m_ulCurrentValue) < 0) m_ulCurrentValue = 0;
- if (m_ulCurrentValue > m_ulMaxValue) m_ulCurrentValue = m_ulMaxValue;
-
- // Breite des blauen streifens berechnen
- int iBreite = arg_ulBarBreite;
- if (m_ulMaxValue)
- {
- iBreite = (arg_ulBarBreite*m_ulCurrentValue)/m_ulMaxValue;
- } // if
-
- int iPosX = arg_ulPosX + arg_ulBreite - arg_ulBarBreite - 1;
- SetAPen(arg_poRPort, m_iPen);
- SetDrMd(arg_poRPort, JAM2);
- RectFill(arg_poRPort,
- iPosX,
- arg_ulPosY,
- iPosX + iBreite,
- arg_ulPosY + arg_ulHoehe);
-
- if (iBreite!=arg_ulBarBreite)
- {
- SetAPen(arg_poRPort, m_iBPen);
- RectFill(arg_poRPort,
- iPosX + iBreite,
- arg_ulPosY,
- iPosX + arg_ulBarBreite,
- arg_ulPosY + arg_ulHoehe);
- } // if
-
- // nun den text ausgeben
- SetAPen(arg_poRPort, 2);
- SetDrMd(arg_poRPort, JAM1);
- switch (m_eProgressMode)
- {
- case PM_Percent:
- { // dummy scope
- int iPercent = (m_ulCurrentValue * 100) / m_ulMaxValue;
- StringC oBuf(10);
- oBuf.formatString("%d%%", iPercent);
- Move(arg_poRPort, iPosX + (arg_ulBarBreite-arg_poTeMe->getTextWidth(oBuf))/2, arg_ulPosY + arg_ulHoehe - 2);
- Text(arg_poRPort, (char *) oBuf, oBuf.getLength());
- } // dummy scope
- break;
- case PM_Absolute:
- { // dummy scope
- StringC oBuf(30);
- oBuf.formatString("%d/%d", m_ulCurrentValue, m_ulMaxValue);
- Move(arg_poRPort, iPosX + (arg_ulBarBreite-arg_poTeMe->getTextWidth(oBuf))/2, arg_ulPosY + arg_ulHoehe - 2);
- Text(arg_poRPort, (char *) oBuf, oBuf.getLength());
- } // dummy scope
- break;
- } // switch
- }
- /*E*/
-
- //******************************************************************//
- //******************************************************************//
- //
- // BarListC
- //
- //******************************************************************//
- //******************************************************************//
- BarListC::BarListC()
- /*S*/
- {
- TRACE("Konstruktor");
- NewList(this);
- m_iBarWidth = 50;
- } // BarListC::BarListC()
- /*E*/
- BarListC::~BarListC()
- /*S*/
- {
- TRACE("Destruktor");
- removeAll();
-
- } // BarListC::~FLXWacthListC()
- /*E*/
- void BarListC::removeAll()
- /*S*/
- {
- TRACE("Entry");
- // wenn die Liste nicht leer ist
- if (!IsListEmpty(this))
- {
- BarNodeC *poNode;
- while (poNode = (BarNodeC *) RemHead(this))
- {
- // Vorgaenger und Nachfolger auf null setzen
- // weil mit RemHead schon removed und der Destruktor
- // das bei nicht nulligen nodes nochmal machen wuerde.
- poNode->ln_Succ = NULL;
- poNode->ln_Pred = NULL;
-
- delete poNode;
- } // while
- } // if
- NewList(this);
- }
- /*E*/
- void BarListC::removeBar(ULONG arg_ulBarID)
- /*S*/
- {
- TRACE("Entry");
- // just find the node an delete it
- BarNodeC *poNode = findBarNode(arg_ulBarID);
- if (poNode)
- {
- delete poNode;
- } // if
- }
- /*E*/
- BarNodeC *BarListC::addBar(char *arg_sName, ULONG arg_ulMaxValue)
- /*S*/
- {
- TRACE("Entry");
-
- // neuen Balken erzeugen
- BarNodeC *poNode = new BarNodeC(this, arg_sName, arg_ulMaxValue);
- if (!poNode)
- {
- TRACE("Kein Speicher");
- return FALSE;
- } // if
- return poNode;
- }
- /*E*/
- BarNodeC *BarListC::findBarNode(ULONG arg_ulBarID)
- /*S*/
- {
- TRACE("Entry");
- BarNodeC *pNode = NULL;
-
- // wenn die Balkenliste nicht leer ist
- if (!IsListEmpty(this))
- {
- pNode = (BarNodeC *) lh_Head;
- do
- {
- if (pNode->m_ulID == arg_ulBarID)
- {
- return pNode;
- } // if
- } while (pNode = pNode->getNext());
- } // if
-
- return pNode;
- }
- /*E*/
- int BarListC::indexOf(BarNodeC *arg_pNode)
- /*S*/
- {
- TRACE("Entry");
-
- // wenn die Balkenliste nicht leer ist
- if (arg_pNode && !IsListEmpty(this))
- {
- int iIndex = 0;
-
- // hole 1. eintrag
- BarNodeC *pNode = (BarNodeC *) lh_Head;
- do
- {
- // wenn gefunden
- if (pNode==arg_pNode)
- {
- return iIndex;
- } // if
-
- iIndex++;
- } while (pNode = pNode->getNext());
- } // if
-
- return -1;
- }
- /*E*/
- BarNodeC *BarListC::operator[](int arg_iIndex)
- /*S*/
- {
- TRACE("ENTRY");
-
- BarNodeC *pNode = NULL;
-
- // wenn die Balken nicht leer ist
- if (!IsListEmpty(this))
- {
- int index = 0;
-
- // hole 1. eintrag
- pNode = (BarNodeC *) lh_Head;
- do
- {
- // wenn i.ten eintrag erreicht
- if (index == arg_iIndex)
- {
- return pNode;
- } // if
-
- index++;
- } while (pNode = pNode->getNext());
- } // if
-
- return pNode;
- }
- /*E*/
- int BarListC::getSize(void)
- /*S*/
- {
- TRACE("Entry");
- int iSize = 0;
-
- // wenn die Liste nicht leer ist
- if (!IsListEmpty(this))
- {
- // hole 1. Eintrag
- BarNodeC *pNode = (BarNodeC *) lh_Head;
- for (iSize=1; pNode = pNode->getNext(); iSize++);
- } // if
-
- return iSize;
- }
- /*E*/
- int BarListC::getHeight(struct Screen *arg_poScreen)
- /*S*/
- {
- TRACE("Entry");
- // Objekt zum ermitteln der Text-hoehe
- TextMeasureC oTeMe(arg_poScreen);
-
- return getSize()*(oTeMe.getTextHeight()+7);
- }
- /*E*/
- int BarListC::getBarTitleWidth(struct Screen *arg_poScreen)
- /*S*/
- {
- TRACE("Entry");
- int iMaxWidth = 0;
-
- TextMeasureC oTeMe(arg_poScreen);
-
- // wenn die Liste nicht leer ist
- if (!IsListEmpty(this))
- {
- // hole 1. Eintrag
- BarNodeC *pNode = (BarNodeC *) lh_Head;
-
- do
- {
- iMaxWidth = SIFC_MAX(iMaxWidth, oTeMe.getTextWidth(pNode->getName()));
- } while (pNode = pNode->getNext());
- } // if
- return iMaxWidth+5;
- }
- /*E*/
- int BarListC::getWidth(struct Screen *arg_poScreen)
- /*S*/
- {
- TRACE("Entry");
- return getBarTitleWidth(arg_poScreen) + m_iBarWidth;
- }
- /*E*/
- void BarListC::drawBars(BarWindowNodeC *arg_poBWNode, ULONG arg_ulPosX, ULONG arg_ulPosY)
- /*S*/
- {
- TRACE("Entry");
- struct Window *poWindow = arg_poBWNode->getWindow();
-
- TextMeasureC oTeMe(poWindow->WScreen);
- int iHoehe = oTeMe.getTextHeight()+6;
- int iBreite = getWidth(poWindow->WScreen);
-
- struct TextFont *poTextFont = OpenFont(poWindow->WScreen->Font); // font oeffne
- struct TextFont *poOldTextFont = poWindow->RPort->Font; // alten sichern
- SetFont(poWindow->RPort, poTextFont); // neuen einstellen
-
- for (int i=0; i<getSize();i++)
- {
- BarNodeC *poBarNode = operator[](i);
- if (poBarNode)
- {
- poBarNode->drawBar(arg_poBWNode,
- &oTeMe,
- arg_ulPosX,
- arg_ulPosY+i*iHoehe,
- m_iBarWidth,
- iBreite,
- iHoehe-4);
- } // if
- } // for
-
- SetFont(poWindow->RPort, poOldTextFont);
- CloseFont(poTextFont);
- }
- /*E*/
- void BarListC::fillBars(BarWindowNodeC *arg_poBWNode, ULONG arg_ulPosX, ULONG arg_ulPosY)
- /*S*/
- {
- TRACE("Entry");
- struct Window *poWindow = arg_poBWNode->getWindow();
-
- TextMeasureC oTeMe(poWindow->WScreen);
- int iHoehe = oTeMe.getTextHeight()+6;
- int iBreite = getWidth(poWindow->WScreen);
-
- struct TextFont *poTextFont = OpenFont(poWindow->WScreen->Font); // font oeffne
- struct TextFont *poOldTextFont = poWindow->RPort->Font; // alten sichern
- SetFont(poWindow->RPort, poTextFont); // neuen einstellen
-
- for (int i=0; i<getSize();i++)
- {
- BarNodeC *poBarNode = operator[](i);
- if (poBarNode)
- {
- poBarNode->fillBar(poWindow->RPort,
- &oTeMe,
- arg_ulPosX,
- arg_ulPosY+i*iHoehe,
- m_iBarWidth,
- iBreite,
- iHoehe-4);
- } // if
- } // for
-
- SetFont(poWindow->RPort, poOldTextFont);
- CloseFont(poTextFont);
- }
- /*E*/
-
-